package org.dk.poitalk.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

import com.google.appengine.api.datastore.Key;

@Entity
@NamedQueries({
	@NamedQuery(name="Survey.findByName", query="SELECT s FROM Survey s WHERE s.name = :name")
})
public class Survey extends DomainEntityImpl implements Serializable {

	private String name;

	@OneToOne(cascade = CascadeType.ALL)
	private Reward reward;

	/**
	 * Constructor
	 * @param id id
	 * @param name name
	 */
	public Survey(Key id, String name) {
		this.setKey(id);
		this.name = name;
	}

	/**
	 * Constructor vacio
	 */
	public Survey() {
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public String toString() {
		return "Survey [name=" + this.name + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Survey other = (Survey) obj;
		if (this.name == null) {
			if (other.name != null)
				return false;
		} 
		return true;
	}

	/**
	 * @return the reward
	 */
	public Reward getReward() {
		return reward;
	}

	/**
	 * @param reward the reward to set
	 */
	public void setReward(Reward reward) {
		this.reward = reward;
	}
}
